package org.ihelpuoo.weboo.security.action;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.ihelpuoo.util.Pager;
import org.ihelpuoo.weboo.action.http.AjaxListAction;
import org.ihelpuoo.weboo.module.ActionContext;
import org.ihelpuoo.weboo.security.RoleObject;
import org.ihelpuoo.weboo.security.Security;

public class QueryRolesAction extends AjaxListAction
{

	@Override
	protected List generateList(ActionContext context, Pager pager) throws Exception
	{
		Security security = Security.me(context.nut());
		Iterator<Integer> it = security.roleIds().iterator();
		List<RoleObject> roles = new LinkedList<RoleObject>();
		while (it.hasNext())
		{
			int id = it.next();
			RoleObject ro = new RoleObject();
			ro.setId(id);
			ro.setName(security.getName(id));
			roles.add(ro);
		}
		return roles;
	}

}
